package com.codeoss.framework.workflow.store;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.codeoss.framework.workflow.def.WorkflowDef;
import com.codeoss.framework.workflow.util.WorkflowUtil;

@Service
public class WorkflowStore implements IWorkflowStore {
	 private Map<String,WorkflowDef> workflowCache=new HashMap<String,WorkflowDef>();
	 @Autowired
	 private WorkflowUtil workflowUtil;
	@Override
	public void put(String workflowWorkflowId, WorkflowDef workflowDef) {
		// TODO Auto-generated method stub
		workflowCache.put(workflowWorkflowId, workflowDef);
	}

	@Override
	public WorkflowDef get(Long workflowWorkflowId) {
		// TODO Auto-generated method stub
		WorkflowDef workflowDef=workflowCache.get(workflowWorkflowId+"");
		if(workflowDef==null) {
			workflowDef=workflowUtil.getWorkflowDefByWorkflowId(workflowWorkflowId);
			workflowCache.put(workflowWorkflowId+"", workflowDef);
		}
		return workflowDef;
	}

	@Override
	public WorkflowDef remove(String workflowWorkflowId) {
		// TODO Auto-generated method stub
		return workflowCache.remove(workflowWorkflowId);
	}

	@Override
	public void clear() {
		// TODO Auto-generated method stub
		workflowCache.clear();
	}

	@Override
	public Map<String, WorkflowDef> getCache() {
		// TODO Auto-generated method stub
		return workflowCache;
	}

}
